package org.xmdl.silk.sample;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.xmdl.SilkStandaloneSetup;
import org.xmdl.silk.Program;
import org.xmdl.silk.interpreter.Interpreter;
import org.xmdl.silk.wrap.ProgramWrap;

public class SampleRunner {

	public static void main(String[] args) {
		System.out.println(args.length + " to run.");
		for (String arg : args) {
			System.out.println("running : " + arg);
			run(arg);
		}
	}

	private static void run(String filename) {
		long t0 = System.currentTimeMillis();
		SilkStandaloneSetup.doSetup();
		ResourceSet resourceSet = new ResourceSetImpl();
		URI uri = URI.createFileURI(filename);
		long t1 = System.currentTimeMillis();
		Resource resource = resourceSet.getResource(uri, true);
		Program prog = (Program) resource.getContents().get(0);
		prog = new ProgramWrap(prog);
		
		long t2 = System.currentTimeMillis();
		Interpreter interpreter = new Interpreter();
		interpreter.run(prog);
		long t3 = System.currentTimeMillis();

		System.out.println("init    : " + (t1 - t0) + "msecs");
		System.out.println("load    : " + (t2 - t1) + "msecs");
		System.out.println("process : " + (t3 - t2) + "msecs");
		System.out.println("total   : " + (t3 - t0) + "msecs");
	}
}
